package edu.tongji.engine.test;

import edu.tongji.engine.db.dao.ProcessDao;
import edu.tongji.engine.def.ActivityNode;
import edu.tongji.engine.def.EndNode;
import edu.tongji.engine.def.ForkNode;
import edu.tongji.engine.def.JoinNode;
import edu.tongji.engine.def.Node;
import edu.tongji.engine.def.ProcessDefinition;
import edu.tongji.engine.def.StartNode;
import edu.tongji.engine.def.Transition;

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

//		Transition t = new Transition();
//		System.out.println(t.getClass().getName());
//		
//		Node node = new ActivityNode();
//		System.out.println(node.getClass().getName());
//		
//		testclass test = new testclass("test");
//		
//		Change change = new Change();
//		change.changeName(test);
//		System.out.println(test.name);
		
		//ProcessService service = new ProcessService();
//		EngineContext context = EngineContext.getEngineContextInstance();
//		ProcessInstance pi = context.createProcessInstance("testprocess");
//		pi.next();
//		pi.next();
//		pi.next();
//		pi.next();
//		pi.next();
		
//		ProcessDao dao = new ProcessDao();
//		ProcessDefinition pd = new ProcessDefinition();
//		pd.setName("process2");
//		
//		Node start = new StartNode();
//		start.setName("start2");
//		start.setPd(pd);
//		pd.setStartNode(start);
//		
//		
//		dao.saveProcessDefition(pd);
		
//		pd = dao.getProcess("process2");
//		System.out.println(pd.getId());
//		System.out.println(pd.getStartNode().getName());
		//dao.deleteProcessDefinition("process1");
		//dao.deleteProcessDefinitionAll();
//		TestDao dao = new TestDao();
//		AbstractTest test = new Test();
//		test.setName("test1");
//		AbstractTest test2 = new Test2();
//		test2.setName("test2");
//		//dao.saveProcess(test);
//		//dao.saveProcess(test2);
//		AbstractTest test3 = dao.getTest("test1");
//		System.out.println(test3.getClass().getName());
//		test3.getClass().getSimpleName();
		ProcessDao dao = new ProcessDao();
		ProcessDefinition pd = new ProcessDefinition();
		
		pd.setName("process1");
		Node start = new StartNode();
		start.setName("start1");
		start.setPd(pd);
		pd.setStartNode(start);
		Node fork1 = new ForkNode();
		fork1.setName("fork1");
		fork1.setPd(pd);
		Node node1 = new ActivityNode();
		node1.setName("node1");
		node1.setPd(pd);
		Node node2 = new ActivityNode();
		node2.setName("node2");
		node2.setPd(pd);
		Node join1 = new JoinNode();
		join1.setName("join1");
		join1.setPd(pd);
		Node end = new EndNode();
		end.setName("end1");
		end.setPd(pd);
		
		Transition trans1 = new Transition();
		trans1.setName("trans1");
		Transition trans2 = new Transition();
		trans2.setName("trans2");
		Transition trans3 = new Transition();
		trans3.setName("trans3");
		Transition trans4 = new Transition();
		trans4.setName("trans4");
		Transition trans5 = new Transition();
		trans5.setName("trans5");
		Transition trans6 = new Transition();
		trans6.setName("trans6");
		
		start.setArrivingTransition(null);
		start.setleavingTransition(trans1);
		fork1.setArrivingTransition(trans1);
		fork1.addLeavingTransition(trans2);
		fork1.addLeavingTransition(trans3);
		node1.setArrivingTransition(trans2);
		node1.setleavingTransition(trans4);
		node2.setArrivingTransition(trans3);
		node2.setleavingTransition(trans5);
		join1.addArrivingTransition(trans4);
		join1.addArrivingTransition(trans5);
		join1.setleavingTransition(trans6);	
		end.setArrivingTransition(trans6);
		end.setleavingTransition(null);
		
		pd.addNode(start);
		pd.addNode(fork1);
		pd.addNode(node1);
		pd.addNode(node2);
		pd.addNode(join1);
		pd.addNode(end);
		
		dao.saveProcessDefition(pd);
	}

}
